﻿using System;

namespace Ycjw.PipeLine.Commons
{
    internal class Log4Logger : ILogger
    {
        private static log4net.ILog log = log4net.LogManager.GetLogger("Log");
        private static log4net.ILog logError = log4net.LogManager.GetLogger("LogError");

        public Log4Logger()
        {
            log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Paths.ApplicationConfigDir + "/log4net.xml"));
        }

        public void Debug(string message)
        {
            try
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug(message);
                }
            }
            catch
            {
            }
        }

        public void Shutdown()
        {
            log4net.LogManager.Shutdown();
        }

        public void Error(Exception ex)
        {
            try
            {
                if (logError.IsErrorEnabled)
                {
                    logError.Error(ex);
                }
            }
            catch
            {
            }
        }

        public void Error(string message)
        {
            try
            {
                if (logError.IsErrorEnabled)
                {
                    logError.Error(message);
                }
            }
            catch
            {
            }
        }

        public void Fatal(Exception ex)
        {
            try
            {
                if (logError.IsFatalEnabled)
                {
                    logError.Fatal(ex);
                }
            }
            catch
            {
            }
        }

        public void Fatal(string message)
        {
            try
            {
                if (logError.IsFatalEnabled)
                {
                    logError.Fatal(message);
                }
            }
            catch
            {
            }
        }

        public void Info(string message)
        {
            try
            {
                if (log.IsInfoEnabled)
                {
                    log.Info(message);
                }
            }
            catch
            {
            }
        }

        public void Trace(string message)
        {
            Debug(message);
        }

        public void Warn(string message)
        {
            try
            {
                if (log.IsWarnEnabled)
                {
                    log.Warn(message);
                }
            }
            catch
            {
            }
        }
    }
}